package com.future.controller;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.future.domain.Manager;
import com.future.domain.Room;
import com.future.dto.ManagerDto;
import com.future.dto.MsgDto;
import com.future.dto.UserForManagerDto;
import com.future.service.ManagerService;
import com.future.service.RoomService;
import com.future.service.UserinfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Auther: 田坑坑
 * @Date: 2022/6/28 21:09
 * @Description: 我题序等你回
 */

@RestController
@RequestMapping("manager")
public class ManagerController {


    @Autowired
    UserinfoService  userinfoService;

    @Autowired
    ManagerService   managerService;


    @Autowired
    RoomService    roomService;



    @RequestMapping("change")
    public MsgDto change(ManagerDto managerDto){

        //如果选择离职，则判断当前宿管是否有管理的宿舍，有的话，无法离职
        // 没有的话，离职成功
        if(managerDto.getManagerStatus().equals("离职")){

            List<ManagerDto>  list1  =   this.managerService.selectManagerDto(managerDto.getId());
            if(list1.size()>0){
                //无法离职
                return   new MsgDto(false,"有管理的宿舍，无法离职");

            }else{

                //成功离职

                Manager  manager   =  new Manager();
                manager.setId(managerDto.getId());
                manager.setManagerstatus(managerDto.getManagerStatus());

                this.managerService.updateById(manager);
                  return   new MsgDto(true,"修改成功");
            }


        }else{
            // 选择在职 就是在职!!!


            Manager  manager   =  new Manager();
            manager.setId(managerDto.getId());
            manager.setManagerstatus(managerDto.getManagerStatus());

             this.managerService.updateById(manager);
            return   new MsgDto(true,"修改成功");

        }


    }




    //分页查询宿管集合
    @RequestMapping("select")
    public PageInfo<UserForManagerDto> select(UserForManagerDto userForManagerDto){


        PageHelper.startPage(userForManagerDto.getCurrent(),userForManagerDto.getSize());
        List list    =   this.userinfoService.userForManager();

        PageInfo pageInfo=new PageInfo(list);


        return pageInfo;


    }
}
